package flc.ast.adapter;

import android.graphics.Color;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.util.Random;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.bean.StkResBean;

public class RankAdapter extends StkProviderMultiAdapter<StkResBean> {

    public RankAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new RankProvider());
    }

    private class RankProvider extends BaseItemProvider<StkResBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_rank;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, StkResBean bean) {
            if (baseViewHolder.getBindingAdapterPosition() == 0) {
                baseViewHolder.setTextColor(R.id.tvRankItemNum, Color.parseColor("#FF0000"));
            } else if (baseViewHolder.getBindingAdapterPosition() == 1) {
                baseViewHolder.setTextColor(R.id.tvRankItemNum, Color.parseColor("#E78415"));
            } else if (baseViewHolder.getBindingAdapterPosition() == 2) {
                baseViewHolder.setTextColor(R.id.tvRankItemNum, Color.parseColor("#F8C01E"));
            } else {
                baseViewHolder.setTextColor(R.id.tvRankItemNum, Color.parseColor("#1F0100"));
            }
            baseViewHolder.setText(R.id.tvRankItemNum, (baseViewHolder.getBindingAdapterPosition() + 1) + "");

            Glide.with(getContext()).load(bean.getThumbUrl())
                    .into((ImageView) baseViewHolder.getView(R.id.ivRankItemImg));
            baseViewHolder.setText(R.id.tvRankItemName, bean.getName());
            baseViewHolder.setText(R.id.tvRankItemDesc, bean.getDesc());

            //评分
            double score = (double) bean.getScore_total() / (bean.getScore_count() == 0 ? 1 : bean.getScore_count());
            String formattedNumber = String.format("%.1f", score);
            baseViewHolder.setText(R.id.tvRankItemScore, getContext().getString(R.string.score_value, formattedNumber));
            Random random = new Random();
            baseViewHolder.setText(R.id.tvRankItemHot, (random.nextInt(10000) + 1000) + "");
        }
    }

}
